;
(function (window, angular) {
    'use strict';
    angular.module("Controller.WorkBoard", [])
        .config(['$stateProvider', function ($stateProvider) {

            $stateProvider.state("app.workBoard.main", {
                url: "/main",
                templateUrl: "view/workBoard/main.html",
                controller: "MainCtrl"
            });

        }])

        .controller("MainCtrl", ["$scope", "ybHttp", "ybWidget", 'ybConfig', "$state", "MESG_TYPE", "EventBus", function ($scope, ybHttp, ybWidget, ybConfig,$state, MESG_TYPE, EventBus) {
            $scope.specialScore = {
                title: {
                    text: '当年销售量和退回量',
                    subtext: '纯属虚构'
                },
                type: "date",
                subType: "safe",
                name: "销售量",
                xData: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
                yData: [
                    {
                        name:'销售量',
                        type:'bar',
                        data:[2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
                    },
                    {
                        name:'退回量',
                        type:'bar',
                        data:[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
                    }
                ]
            };
            $scope.backlogData = {
                applyCount:0
            };
            $scope.btnPermission = {
                applyAudit: false,
                company: false,
                organize: false,
                role: false,
                user: false
            };
            var btnPermission = {
                applyAudit: "app.merchant.applyAudit",
                company: "app.merchant.company",
                organize: "app.internal.organize",
                role: "app.internal.role",
                user: "app.internal.user"
            };

            $scope.getSubNav = function (navName) {
                $state.go(navName);
                EventBus.Publish("getSubNav", navName);
            };

            function getData() {
                var service = "device";
                var reqUrl = "/workBoard/applyCount";
                var param = {};
                ybHttp.Get(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    $scope.backlogData.applyCount=resp.value;
                    if(resp.value>99){
                        $scope.backlogData.applyCount="99+";
                    }

                });
            }

            function getMenuList() {
                var service = "auth";
                var reqUrl = "/menu/listAuthorized";
                ybHttp.Get(service, reqUrl).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp.message);
                        return;
                    }
                    checkBtnPermission(resp.value);
                });
            }

            function checkBtnPermission(permissionMenu) {
                for (var key in btnPermission) {
                    for (var i = 0, len = permissionMenu.length; i < len; i++) {
                        if (btnPermission[key] == permissionMenu[i].state) {
                            $scope.btnPermission[key] = true;
                            break;
                        }
                        $scope.btnPermission[key] = false;
                    }
                }
            }
            (function () {
                getData();
                getMenuList();
            })();

        }])
    ;
})(window, window.angular);